package com.example.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dao.UsersDao;
import com.example.domain.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UsersDao usersDao;

    public Users login(Users users){
        QueryWrapper<Users> qw = new QueryWrapper<>();
        qw.eq("username",users.getUsername()).eq("password",users.getPassword());
        Users login_user = usersDao.selectOne(qw);
        return login_user;
    }

    public boolean register(Users user){
        QueryWrapper<Users> qw = new QueryWrapper<>();
        qw.eq("username",user.getUsername());
        Users users = usersDao.selectOne(qw);
        if(users!=null){
            return false;
        }
        usersDao.insert(user);
        return true;
    }

    public Users selectByUsername(String username){
        QueryWrapper<Users> qw = new QueryWrapper<>();
        qw.eq("username",username);
        return usersDao.selectOne(qw);
    }

}
